package ru.susu.algebra.centralunits.alternating;

import java.math.BigInteger;

import ru.susu.algebra.chartable.constructor.AlternatingGroupCharTableConstructor;
import ru.susu.algebra.field.quadratic.QuadraticInteger;
import ru.susu.algebra.field.quadratic.QuadraticIntegerExtractor;
import ru.susu.algebra.jtex.StringTexElement;
import ru.susu.algebra.jtex.formula.FormulaTexElement;
import ru.susu.algebra.partition.Partition;

/**
 * @author akargapolov
 * @since: 16.07.2010
 */
public class AlternatingCentralUnitsUtils
{
	public static boolean isGoodCharacterForUnit(Partition row, Partition col)
	{
		try
		{
			QuadraticIntegerExtractor extractor = QuadraticIntegerExtractor.getInstance();
			QuadraticInteger qinteger = extractor.apply(AlternatingGroupCharTableConstructor.getInstance().getValue(
					row, col).getValue(0, 0));
			return qinteger.getD().compareTo(BigInteger.ZERO) > 0;
		}
		catch (Exception e)
		{
			throw new RuntimeException(e);
		}
	}

	public static FormulaTexElement getAnFormula(int number)
	{
		return (FormulaTexElement)FormulaTexElement.formula().addSubElement(StringTexElement.text("A_{" + number + "}"));
	}

	public static FormulaTexElement getUZZAnFormula(int number)
	{
		return (FormulaTexElement)FormulaTexElement.formula().addSubElement(StringTexElement.text("U\\left(Z\\left(ZA_{" + number + "}\\right)\\right)"));
	}
}
